package com.pams.controller;
import com.pams.pojo.entity.Note;
import com.pams.result.Result;
import com.pams.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/api/note")
public class NoteController {
    @Autowired
    private NoteService noteService;
    @PutMapping("/add")
    public Result<Integer>  add(@RequestBody Note note){
        int id =  noteService.add(note);
        return Result.success(id);
    }

    @GetMapping("/query")
    public Result<List<Note>> getlist(){
        List<Note> list = noteService.getlist();
        return Result.success(list);
    }

    @GetMapping("/")
    public Result<Note> getSelectedNote(@RequestParam int id ){
        Note note =   noteService.getSelectedNote(id);
        return Result.success(note);
    }

    @DeleteMapping("/delete")
    public Result delete(@RequestParam int id){
        noteService.delete(id);
        return Result.success();
    }
    @GetMapping("/search")
    public Result<List<Note>> search(@RequestParam String title){
        List<Note> list = noteService.search(title);
        return Result.success(list);
    }

}
